package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClassBean;
import com.project.service.ClassService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小班
 */
@Controller
@RequestMapping("class")
public class ClassController {


    @Resource
    private ClassService classService;


    /**
     * 分页显示
     * @param pageNO
     * @param pageSize
     * @return
     */
    @RequestMapping("findAllClass")
    @ResponseBody
    public IPage<ClassBean> findAllClass(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                         @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return classService.findAllClass(pageNO, pageSize);
    }


    /**
     * 添加
     * @param classBean
     * @return
     */
    @RequestMapping("addClass")
    @ResponseBody
    public String addClass(ClassBean classBean) {
        classService.addClass(classBean);
        return "添加成功";
    }

    /**
     * id查询
     * @param classId
     * @return
     */
    @RequestMapping("findId")
    @ResponseBody
    public ClassBean findId(int classId) {
        return classService.findId(classId);
    }


    /**
     * id修改负责人和电话
     * @param classId
     * @param classPerson
     * @param classPersonTel
     * @return
     */
    @RequestMapping("updateClass")
    @ResponseBody
    public String updateClass(int classId, String classPerson, String classPersonTel) {
        classService.updateClass(classId, classPerson, classPersonTel);
        return "修改成功";
    }

    /**
     * 小班名区域模糊查询
     * @param pageNO
     * @param pageSize
     * @param className
     * @param regionId
     * @return
     */
    @RequestMapping("findName")
    @ResponseBody
    public List<ClassBean> findName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String className, String regionId) {
        return classService.findName(className,regionId);
    }

}
